/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import java.util.ArrayList;


public class KeywordParser {

    private boolean blockOpen = false;
    private char delimiter = ' ';
    private char blockDelimiter = '"';


    public ArrayList<String> parseAll(String input) {
        ArrayList<String> tmpParsed = new ArrayList<String>();
        int count = 0;
        input = input.trim();
        String tmp = "";

        for (int i = 0; i < input.length(); i++) {
            if (input.charAt(i) == delimiter && !blockOpen) {
                count++;
                if (!tmp.equals("")) {
                    tmpParsed.add(tmp);
                    tmp = "";
                }
                continue;
            }
            if (input.charAt(i) == blockDelimiter) {
                blockOpen = !blockOpen;
                continue;
            }
            tmp = tmp.concat(String.valueOf(input.charAt(i)));

            if (i == input.length()-1 && !tmp.equals("")) {
                tmpParsed.add(tmp);
                tmp = "";
            }
        }
        
        return tmpParsed;
    }
}
